﻿$(document).on("pageInit", "#teacher-apply-list", function (e, id, page) {
    loadList();

    function loadList() {
        $(page).find("#list").empty();
        $.getJSON("/Apply/GetApplyList", {}, function (response) {
            var statusEnum = {
                2: "审批中",
                3: "已拒绝",
                4: "已通过"
            };
            $.each(response, function (index, item) {
                var frame = $('<li>\
                    <a href="/Apply/Detail4Teacher/' + item.Id + '" class="item-link item-content" data-no-cache="true">\
                        <div class="item-inner">\
                            <div class="item-title-row">\
                                <div class="item-title">' + item.Title + '</div>\
                                <div class="item-after">' + item.ApplyTime + '</div>\
                            </div>\
                            <div class="item-subtitle">申请人：' + item.ApplyRealName + '</div>\
                            <div class="item-subtitle">状态：' + statusEnum[item.Status] + '</div>\
                            <div class="item-text">备注：' + (item.ApplyRemark || '') + '</div>\
                        </div>\
                    </a>\
                </li>');
                $(page).find("#list").append(frame);
            });
        });
    }

    $(page).find("#menu-btn").on("click", function () {
        var buttons1 = [
        {
            text: '请选择',
            label: true
        }, {
            text: '创建请假申请',
            bold: true,
            onClick: function () {
                $.router.load('/apply/create', true);
            }
        }];

        var buttons2 = [
          {
              text: '取消',
              bg: 'danger'
          }
        ];
        var groups = [buttons1, buttons2];
        $.actions(groups);
    });
});